<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\DB;

class PostType extends Model
{
    
    protected $table = 'post_type';
    protected $primaryKey = 'post_type_id';
    public $incrementing = true;
    protected $hidden = [];
    protected $guarded = [];

//    protected $fillable = ['edid','eid','CurrentHumidity','CurrentTemperature','LightLux','SoilMoisture','SoilTemperature','soilEC','Time','RequestId','greenhouseName','cropName','ctime', 'mtime','dtime','gid'];
    public $timestamps = false;

    public static function getList($where,$limit)
    {

        $data = DB::table('post_type as pt')
            ->orderBy('pt.post_type_id','desc');


        if(!empty($where['name']))
        {
            $data->where('pt.post_type_name','like','%'.$where['name'].'%');
        }

        if(!empty($where['code']))
        {
            $data->where('pt.post_type_code',$where['code']);
        }
        if(!empty($where['status']))
        {
            $data->where('pt.status',$where['status']);
        }
        if(!empty($where['company_id']))
        {
            $data->where('pt.company_id',$where['company_id']);
        }

        return $data->paginate($limit);
    }


}